package top.kaoshanji.p1ch04a;

/**
 * 代码清单-p1ch04a-060页a：默认的equals()方法并不是比较内容的
 * author kaoshanji
 * ^_^
 * create time 2025/3/6 18:57
 */
public class EqualsMethod {

    public static void main(String[] args) {
        ValA va1 = new ValA();
        ValA va2 = new ValA();

        va1.i = va2.i = 100;
        System.out.println(va1.equals(va2)); // 默认

        ValB vb1 = new ValB();
        ValB vb2 = new ValB();
        vb1.i = vb2.i = 100;
        System.out.println(vb1.equals(vb2)); // 自定义

    }

}

class ValA {
    int i;
}

class ValB {
    int i;

    public boolean equals(Object o) {
        ValB rval = (ValB) o;
        return i == rval.i;
    }

}
